def knapsack_backtracking(W, weights, values, N, index=0, current_weight=0, current_value=0, best_value=0, best_items=[]):
    if index == N or current_weight >= W:
        if current_value > best_value:
            return current_value, best_items
        return best_value, best_items
    
    # 不选当前物品
    best_value, best_items = knapsack_backtracking(
        W, weights, values, N, index + 1, current_weight, current_value, best_value, best_items
    )
    
    # 选当前物品（如果不超过容量）
    if current_weight + weights[index] <= W:
        new_value, new_items = knapsack_backtracking(
            W, weights, values, N, index + 1,
            current_weight + weights[index], current_value + values[index],
            best_value, best_items + [(weights[index], values[index])]
        )
        if new_value > best_value:
            best_value, best_items = new_value, new_items
    
    return best_value, best_items

# 示例
W = 10
weights = [2, 3, 4, 5]
values = [3, 4, 5, 6]
N = len(weights)
max_val, items = knapsack_backtracking(W, weights, values, N)
print("最大价值（回溯）:", max_val)  # 10
print("选择的物品:", items)